<?php
$orderby = get_major_key(array('rank' => 'DESC', 'id' => 'DESC'), null, 'id');
$categorys = cache_read('goods_categorys.php');
$oFavorite = new Favorite();

if(!empty($_GET['btnExport'])){	// 导出
	$list = $oFavorite->get_list('*', $_GET, $orderby, 1, 65536, $offset = 0);
	if(!empty($list['list']) && is_array($list['list'])){
		$data = array();
		foreach($list['list'] as $row){
			$row['time'] = ftime($row['addtime']);
			$data[] = $row;
		}
		$headers = array(
			'id'		=> array('title' => 'ID',	'width' => '6'),
			'goodsname'	=> array('title' => '商品', 'width' => '50', 'wrap' => true),
			'price'		=> array('title' => '价格（￥）', 'width' => '12.5'),
			'time'		=> array('title' => '时间', 'width' => '18'),
		);
		if($list['total'] > 5000){	// 导出超过5000时用CSV
			export_csv($data, $headers, '_E_收藏_'.date('Ymd_His').'.csv');
		}else{
			$oExcel = new Excel();
			$oExcel->export($headers, $data, '_E_收藏_'.date('Ymd_His').'.xlsx');
		}
	}
	exit;
}

#

$list = $oFavorite->get_list('*', $_GET, $orderby, $__page, $__pagesize);
if(!empty($list['list'])){
	// 主键排序字段
	make_major_key_options(array(
		'id'		=> '添加时间',
		'price'		=> '价格',
	));

	foreach($list['list'] as $key => $row){
		$row['addtime'] = ftime($row['addtime']);
		if(empty($row['goodsinfo']['filename'])){
			$row['goodsinfo']['url'] = PUB_DIR.'goods/'.time_to_path($row['goodsinfo']['addtime']).'/'.$row['goodsinfo']['id'].'.html';
		}else{
			$row['goodsinfo']['url'] = PUB_DIR.'goods/'.$row['goodsinfo']['filename'].'.html';
		}

		$list['list'][$key] = $row;
	}
	$vars['list'] = $list['list'];
	$vars['pagelist'] = $list['pagelist'];
}
?>